//@flow

//类型推断   根据代码推断出 变量的类型
function square(n: number) {
  return n * n;
}

square(5);

//类型注解  标记变量的类型 函数返回值
let num: number = 100;

function getSum(): number {
  return 1;
}

// 原始类型
// string number undefined null symbol

const a: string = "lx";
const b: number = NaN; // NaN 100 Infinity
const c: null = null;
const d: boolean = false;
const e: void = undefined;
const f: symbol = Symbol();

//数组类型
const arr1: Array<number> = [1];
const arr2: number[] = [1];
const arr3: [string, number] = ["1", 2]; //元祖

// 对象类型
const obj1: { name: string, age?: number } = { name: "lx" };
const obj2: { [key: string]: string } = {};

//函数类型
function foo(callback: (number, string) => void) {
  callback(18, "lx");
}
foo((age, name) => {});

//特殊类型
// 字面量类型
const a1: "foo" = "foo";
const type: "success" | "danger" | "warning" = "success";
type StringOrNumber = string | number;
const b1: StringOrNumber = "lx";
const gener: ?number = null; //maybe 类型

// mixed 与 any
// mixed 表示所有类型的联合类型  会有安全检查
// any表示忽略检查
function f1(str: mixed) {
  //   str * str;
}
f1("lx");
f1(24);
